<?php
class ModelCommunityProfile extends Model{
    public function getMemberInfo($getData){
        $query=$this->db->query("SELECT u.username, u.user_type, u.user_avatar, u.user_ip, u.user_regdate, u.user_lastvisit, u.user_lastpost_time, u.user_topics, u.user_posts, u.user_from, u.user_icq, u.user_aim, u.user_yim, u.user_msnm, u.user_jabber, u.user_occ, u.user_interests, u.user_birthday, u.user_actkey, rt.role_title, rat.rank_title FROM " . DB_PREFIX . "community_users AS u LEFT JOIN " . DB_PREFIX . "community_role_title AS rt on (rt.role_id=u.user_type AND rt.language_id='" . (int)$this->config->get('config_language_id') . "') LEFT JOIN " . DB_PREFIX . "community_rank_title AS rat ON (rat.rank_id=u.user_rank AND rat.language_id='" . (int)$this->config->get('config_language_id') . "') WHERE u.user_id='" . (int)$getData['uid'] . "' LIMIT 0,1");

        return $query->row;
    }

    public function getTopicTotal($getData){
        $query=$this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "community_topics WHERE topic_poster_id='" . (int)$getData['uid'] . "' AND topic_approved='1' AND topic_deleted='0'");
        return $query->row['total'];
    }

    public function getTopicInfo($getData,$start,$limit){
        $query=$this->db->query("SELECT t.forum_id, t.topic_type, t.topic_id, t.topic_title, t.topic_time, t.topic_replies, t.topic_views, t.topic_last_poster_id, t.topic_last_poster_name, t.topic_last_post_time, fn.forum_name, tt.mark_time FROM " . DB_PREFIX . "community_topics AS t LEFT JOIN " . DB_PREFIX . "community_forum_name_des_rule AS fn ON (fn.forum_id=t.forum_id AND fn.language_id='" . (int)$this->config->get('config_language_id') . "') LEFT JOIN " . DB_PREFIX . "community_topics_track AS tt ON (t.topic_id=tt.topic_id AND t.topic_poster_id=tt.user_id) WHERE t.topic_poster_id='" . (int)$getData['uid'] . "' AND t.topic_approved='1' AND t.topic_deleted='0' ORDER BY t.topic_last_post_time DESC LIMIT " . $start . ", " . $limit);

        return $query->rows;
    }

    public function getPostTotal($getData){
        $query=$this->db->query("SELECT COUNT(*) AS total FROM " . DB_PREFIX . "community_posts WHERE poster_id='" . (int)$getData['uid'] . "' AND post_approved='1' AND post_deleted='0' AND post_id NOT IN (SELECT topic_first_post_id FROM " . DB_PREFIX . "community_topics WHERE topic_poster_id='" . (int)$getData['uid'] . "')");

        return $query->row['total'];
    }

    public function getPostInfo($getData,$start,$limit){
       $query=$this->db->query("SELECT forum_id, topic_id, post_id, post_subject, post_time, post_text FROM " . DB_PREFIX . "community_posts WHERE poster_id='" . (int)$getData['uid'] . "' AND post_approved='1' AND post_deleted='0' AND post_id NOT IN (SELECT topic_first_post_id FROM " . DB_PREFIX . "community_topics WHERE topic_poster_id='" . (int)$getData['uid'] . "') ORDER BY post_time DESC LIMIT " . $start . ", " . $limit);

        return $query->rows;
    }
}
?>